{extend name="index/index" /}


{block name="main"}

<div class="admin-biaogelist">
	
    <div class="listbiaoti am-cf">
        <ul class="am-icon-users"> 角色管理</ul>
        <dl class="am-icon-home" style="float: right;">当前位置： 首页 > <a href="#">角色列表</a></dl>
        <dl>
             <a href="{:url('admin/role/create')}"  class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus" > 手动添加角色</a>
        </dl>
      <!--这里打开的是新页面-->
    </div>

    <form class="am-form am-g">
          <table width="100%" class="am-table am-table-bordered am-table-radius am-table-striped" align="center">
            <thead>
              <tr class="am-success">
                  <th class="table-id">ID</th>
                  <th class="">角色名称</th>
                  <th class="">职责描述</th>
                  <th class="">状态</th>
                  <th class="col-md-2">权限分配</th>
                  <th class="col-md-2">操作</th>
              </tr>
            </thead>
            <tbody>

            {volist name="data" id="vo"}
              <tr>
                  <td>{$vo.id}</td>
                  <td>{$vo.rolename}</td>
                  <td>{$vo.remark}</td>
                  <td>{if condition="$vo.status eq 1"}启用
                      {else /} 禁用
                      {/if}</td>
                  <td>
                      <a href="{:url('admin/Role/getnode',['id'=>$vo['id']])}"><span>配置权限</span></a>
                  </td>
                  <td>
                      <a href="{:url('admin/Role/edit',['id'=>$vo['id']])}">修改</a>
                      <div class="am-btn-group">
                        <button data_id="{$vo.id}" class="del-btn am-btn am-btn-default am-btn-xs am-text-danger am-round">删除</button>
                      </div>
                  </td>
              </tr>
            {/volist}

            </tbody>
          </table>
          <ul class="am-pagination am-fr">
              {$data->render()}
          </ul>
        </form>
</div>

<script>

    $(function () {
        //触发用户的删除操作
        $('.del-btn').click(function () {
            var ac_id = $(this).attr('data_id');
            //弹出提示框
            if (confirm('你确定要 [ 删除 ] 该角色么?')) {
                var obj = $(this).parents('tr');
                // 调用执行AJAX删除
                delAjax(ac_id, obj);
            }
        });
    });
    // 执行AJAX删除
    function delAjax(id, obj) {
        $.ajax({
            type: 'delete',
            url: '/roles/' + id,
            dataType: 'json',
            //数据删除成功后，移除该节点
            success: function (data) {
                console.log(data);
                    obj.remove();
            },
            error: function () {
                // AJAX操作失败
                alert('AJAX操作失败');
            }
        });
    }
</script>
{/block}




